#include <iostream>

using namespace std;

const int N = 1010, M = 20010;

int f[N][M], num[M], q[M];

int main() {
    int n, V;
    cin >> n >> V;
    
    for (int i = 1; i <= n; ++ i) {
        int v, w, s;
        cin >> v >> w >> s;
        
        for (int d = 0; d < v; ++ d) {
            int hh = 0, tt = -1;
            for (int j = 0; j <= (V - d) / v; ++ j) {
                int term = f[i - 1][d + j * v] - j * w;
                while (hh <= tt && j - num[hh] > s) hh ++ ;
                while (hh <= tt && q[tt] <= term) tt -- ;
                q[ ++ tt] = term;
                num[tt] = j;
                f[i][d + j * v] = q[hh] + j * w;
            }
        }
    }
    
    cout << f[n][V] << endl;
    
    return 0;
}